package com.dxy.yzs.marathon.controller;

import com.dxy.yzs.marathon.common.R;
import com.dxy.yzs.marathon.common.log.annotation.LogAnnotation;
import com.dxy.yzs.marathon.domain.User;
import com.dxy.yzs.marathon.service.UserService;
import com.dxy.yzs.marathon.vo.MessageContactVO;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * class description
 *
 * @author zhangxunwei
 * @date 2021/10/22
 */
@RestController
@AllArgsConstructor
public class LoginController {
    private final UserService userService;

    @LogAnnotation(module = "user")
    @PostMapping("/login")
    public R login(@RequestBody Map<String, String> params) {
        String username = params.get("username");
        String password = params.get("password");
        User user = userService.login(username, password);
        return R.ok().put("data",user);
    }

    /**
     * 获取除了 当前登录 的所有用户【所有用户列表】
     * @param loginUser
     * @return
     */
    @LogAnnotation(module = "user")
    @GetMapping("getAllUsersExcept")
    public R getAllUsersExcept(@RequestBody User loginUser){
        List<User> otherUsers = userService.getAllUsersExcept(loginUser);
        return R.ok().put("data",otherUsers);
    }

    /**
     * 获取当前用户所有联系人和其消息
     * @param loginUser
     * @return
     */
    @LogAnnotation(module = "user")
    @GetMapping("getContacts")
    public R getContacts(@RequestBody User loginUser){
        MessageContactVO contactVO = userService.getContacts(loginUser);
        return R.ok().put("data",contactVO);
    }

}
